package com.parkinglot.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.parkinglot.core.Result;
import com.parkinglot.parmeter.GarageMonthConfigParm;
import com.parkinglot.parmeter.MohuqueryParm;
import com.parkinglot.parmeter.MonthRecordParm;
import com.parkinglot.parmeter.UserqueryParm;
import com.parkinglot.pojo.MonthbilRecord;
import com.parkinglot.service.GarageMonthConfigService;
import com.parkinglot.service.MonthbilRecordService;
import com.parkinglot.vo.MonthbillUserRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("monthrecord")
@Slf4j
@Api(tags = "月票记录接口")
public class MonthRecordController {

    @Resource
    private MonthbilRecordService monthbilRecordService;
    @Resource
    private GarageMonthConfigService garageMonthConfigService;

    @ApiOperation(value = "月票会员记录（根据会员手机号查询会员月票交费记录）")
    @GetMapping("/getmonthrecord")
    public Result getmonthrecord(UserqueryParm userqueryParm){
        return Result.success(monthbilRecordService.getmonthrecord(userqueryParm));
    }

    @ApiOperation(value = "月票退款信息核对（根据手机号查询月票退款记录方便核对退款金额信息）")
    @GetMapping("/getmonthtuikuan")
    public Result getmonthtuikuan(UserqueryParm userqueryParm){
        return Result.success(monthbilRecordService.getmonthtuikuan(userqueryParm));
    }

   /* @ApiOperation(value = "统计所有会员数量")
    @GetMapping("/countvip")
    public Result countvip(MonthbilRecord monthbilRecord){
        return Result.success(monthbilRecordService.countvip(monthbilRecord));
    }*/

    @ApiOperation(value = "统计某个停车场下会员数量")
    @GetMapping("/countgaragevip")
    public Result coungaragetvip(MonthRecordParm monthbilRecord){
        return Result.success(monthbilRecordService.coungaragetvip(monthbilRecord));
    }

  /*  @ApiOperation(value = "统计某个停车场下会员记录(月票统计 用户总量)")
    @GetMapping("/countgarageuservip")
    public Result coungarageusertvip(String  garagecode){
        return Result.success(monthbilRecordService.coungarageusertvip(garagecode));
    }*/

    @ApiOperation(value = "统计某个停车场下会员记录(月票统计 用户总量)")
    @GetMapping("/countgarageuservip")
    public Result coungarageusertvip(MohuqueryParm mohuqueryParm, int page, int limit){
        PageHelper.startPage(page, limit);
        List<MonthbillUserRecordVo> list= monthbilRecordService.coungarageusertvip(mohuqueryParm);
        return Result.success(new PageInfo<MonthbillUserRecordVo>(list));
    }
    @ApiOperation(value = "新增月票订单")
    @PostMapping("/monthorder")
    public Result monthorder(MonthRecordParm monthRecordParm){

        return Result.success(monthbilRecordService.insertoverride(monthRecordParm));
    }
    @ApiOperation(value = "修改月票信息")
    @PostMapping("/updatemonthorder")
    public Result updatemonthorder(MonthRecordParm monthRecordParm){
        MonthbilRecord monthbilRecord=new MonthbilRecord();
        BeanUtils.copyProperties(monthRecordParm,monthbilRecord);
        return Result.success(monthbilRecordService.update(monthbilRecord));
    }

    @ApiOperation(value = "新增月票规则配置")
    @PostMapping("/addmonthconfig")
    public Result addmonthconfig(GarageMonthConfigParm garageMonthConfigParm){

        return Result.success(garageMonthConfigService.addmonthconfig(garageMonthConfigParm));
    }

    @ApiOperation(value = "查询月票价格和规则")
    @GetMapping("/getmonthconfig")
    public Result getmonthconfig(  String garageid){

        return Result.success(garageMonthConfigService.queryAll(garageid));
    }

    @ApiOperation(value = "查询用户开通的月票")
    @GetMapping("/getusermonthvip")
    public Result getusermonthvip(  String garageid,String userid){
    //TODO
        return Result.success();
    }

    /**
     * 查询用户每个车是不是会员 针对用户绑定多辆车
     */
    //getusercarisvip
    @ApiOperation(value = "查询用户每个车是不是会员 针对用户绑定多辆车")
    @GetMapping("/getusercarisvip")
    public Result getusercarisvip(  String garageid,String userid,String carnumber){

        return Result.success(monthbilRecordService.getusercarisvip(garageid,userid,carnumber));
    }
}
